import { ref } from 'vue'
import { defineStore } from 'pinia'
import { searchGoodsById, searchGoodsImageById } from '@/api/detail'
import { detail, image } from '@/model/detailModel'

export default defineStore('detail', () => {
  const detail = ref<detail>()
  const getGoodsDetail = async (goods_id: number) => {
    const result = await searchGoodsById(goods_id)
    if (result.status === 200) detail.value = result.data
  }
  const imageList = ref<image[]>()
  const getGoodsImageList = async (goods_id: number) => {
    const result = await searchGoodsImageById(goods_id)
    if (result.status === 200) imageList.value = result.data
  }
  return {
    detail,
    getGoodsDetail,
    imageList,
    getGoodsImageList
  }
})
